<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="webkit" name="renderer"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Cache-Control"
          content="no-cache, no-store, must-revalidate"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <meta http-equiv="Expires" content="0"/>
    <meta content="width=device-width, initial-scale=1, user-scalable=1"
          name="viewport"/>
    <title>注册 - 农业物资管理系统</title>
    <meta name="keywords" content=""/>
    <meta name="description"
          content=""/>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/png">
    <script src="js/jquery/jquery-1.12.4.min.js"></script>
    <!--[if lt IE 9]>
    <script src="js/common/h5fix.min.js"></script><![endif]-->
    <link rel="stylesheet" href="css/fonts/font-icons.min.css">
    <link rel="stylesheet" href="js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="js/adminlte/css/AdminLTE.min.css">
    <link rel="stylesheet" href="css/jsherp.css">
    <link rel="stylesheet" href="js/adminlte/css/skins/skin-blue-light2.css">
    <link rel="stylesheet" href="js/modules/sys/sysRegister.css">
    <script type="text/javascript" src="js/common/common.js"></script>
    <script type="text/javascript" src="js/md5/md5.js"></script>
    <script type="text/javascript" src="js/gVerify.js"></script>
    <!-- 确保引入 Font Awesome 图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body class="hold-transition register-page">
<div class="wrapper">
    <!--[if lte IE 9]><a style="position:absolute;top:0;left:0;z-index:100000;display:block;width:100%;font-size:14px;
    color:#F00;text-decoration:none;background-color:#faffb3;text-align:center;"
                         href="js/upbw/index.html" target="_blank">您的浏览器版本过低或在兼容模式下，导致打开速度过慢，提升速度您可以切换到极速模式或升级为最新版，点击此处查看详情。</a>
    <![endif]-->
    <!--[if lte IE 8]>
    <script>window.location.href = 'js/upbw/index.html';</script><![endif]-->
    <!-- <link rel="stylesheet" href="js/static/icheck/1.0/square/blue.css"> -->
    <link rel="stylesheet" href="js/modules/sys/sysLogin.css">
    <div class="register-box">
        <div class="register-logo">
            <a href="/">
                <b>农业物资管理系统</b>
                <b>
                    <small>V2.1</small>
                </b>
            </a>
        </div>
        <div class="register-box-body">
            <div class="form-group has-feedback">
                <span class="glyphicon glyphicon-user form-control-feedback"
                      title="登录账户"></span>
                <input type="text" id="loginName" name="loginName"
                       class="form-control required"
                       data-msg-required="请填写登录账号."
                       placeholder="登录账户 （请输入手机号码）"/>
            </div>
            <div class="form-group has-feedback">
                <!-- 登录密码输入框，眼睛图标根据状态切换 -->
                <span class="fa fa-eye-slash form-control-feedback"
                      title="点击显示/隐藏密码"
                      onclick="togglePasswordVisibility('password', 'passwordVisibilityIcon')"
                      id="passwordVisibilityIcon">
                </span>
                <input type="password" id="password" name="password"
                       class="form-control required"
                       data-msg-required="请填写登录密码." placeholder="登录密码"
                       autocomplete="off"/>
            </div>
            <div class="form-group has-feedback">
                <!-- 确认密码输入框，眼睛图标根据状态切换 -->
                <span class="fa fa-eye-slash form-control-feedback"
                      title="点击显示/隐藏密码"
                      onclick="togglePasswordVisibility('confirmPassword', 'confirmPasswordVisibilityIcon')"
                      id="confirmPasswordVisibilityIcon">
                </span>
                <input type="password" id="confirmPassword"
                       name="confirmPassword" class="form-control required"
                       data-msg-required="请填写确认密码." placeholder="确认密码"
                       autocomplete="off"/>
            </div>
            <div class="form-group has-feedback" id="isValidCodeLogin">
                <div class="input-group">
                    <span class="input-group-addon">验证码：</span>
                    <input type="text" id="validCode" name="validCode"
                           class="form-control" required="true"
                           data-msg-required="请填写验证码"
                           data-msg-remote="验证码不正确."/>
                    <span class="input-group-addon p0">
                        <div id="imgCaptcha" title="点击刷新验证码"></div>
                    </span>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="__url" value="">
                <button type="submit" class="btn btn-primary btn-block btn-flat"
                        id="btnSubmit" data-loading="注册验证成功，正在进入..."
                        data-register-valid="正在验证注册，请稍候...">立即注册
                </button>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <a href="login.html" class="pull-left"><b>[ 立即登录 ]</b></a>
                    <div class="dropdown pull-right">
                        <a href="javascript:void(0);"
                           class="dropdown-toggle">
                            <b><i class="fa icon-globe"></i> 官方网站</b>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="register-copyright">
            &copy; 2025 河南农业大学
            <a style="color:#00458a;" href="javascript:void(0);">河南农业大学农业物资管理系统</a>
            <a style="color:#00458a;" href="javascript:void(0);"></a>
            <a style="color:#00458a;"
               href="javascript:void(0);"></a>
        </div>
    </div>
</div>
</body>

<script>
    $("#loginName, #password, #confirmPassword").on("focus blur", function () {
        var a = this;
        setTimeout(function () {
            var b = $(a).css("borderColor");
            if (b != "") {
                $(a).prev().css("color", b)
            }
        }, 100)
    }).blur();
    var verifyCode = new GVerify("imgCaptcha");
    //注册按钮绑定处理事件
    $("#btnSubmit").off("click").on("click", function () {
        if ($("#validCode").val()) {
            var res = verifyCode.validate($("#validCode").val());
            if (res) {
                var loginName = $("#loginName");
                if (!loginName.val()) {
                    alert("登录账户不能为空!");
                } else if (!isPhoneAvailable(loginName)) {
                    alert("请输入正确的手机号码!");
                } else if (!$("#password").val()) {
                    alert("登录密码不能为空!");
                } else if (!$("#confirmPassword").val()) {
                    alert("确认密码不能为空!");
                } else if ($("#password").val() != $("#confirmPassword").val()) {
                    $("#confirmPassword").val("");
                    alert("确认密码不一致!");
                } else {
                    //执行注册
                    $.ajax({
                        type: "post",
                        url: "/user/registerUser",
                        dataType: "json",
                        data: ({
                            loginName: $("#loginName").val(),
                            password: $("#password").val()
                        }),
                        success: function (res) {
                            if (res && res.code === 200) {
                                alert("注册成功，请进行登录！");
                                location.href = "login.html";
                            } else {
                                alert(res.msg);
                                verifyCode.refresh(); //刷新
                            }
                        },
                        //此处添加错误处理
                        error: function () {
                            alert("后台访问错误，请联系管理员！");
                        }
                    });
                }
            } else {
                alert("验证码错误!");
            }
        } else {
            alert("验证码为空!");
        }
    });

    function togglePasswordVisibility(inputId, iconId) {
        const passwordInput = document.getElementById(inputId);
        const icon = document.getElementById(iconId);
        // 切换密码输入框的 type 属性
        if (passwordInput.type === 'password') {
            passwordInput.type = 'text';
            icon.classList.remove('fa-eye-slash');
            icon.classList.add('fa-eye');
        } else {
            passwordInput.type = 'password';
            icon.classList.remove('fa-eye');
            icon.classList.add('fa-eye-slash');
        }
    }
</script>

</html>